package com.tongna.crawler.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import com.tongna.crawler.Apps;
import jodd.http.HttpRequest;
import jodd.http.HttpResponse;

public class AppServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		try {
			final Long id = Long.valueOf(request.getParameter("id"));
			final Long cid = Long.valueOf(request.getParameter("cid"));
			new Thread(new Runnable() {
				
				public void run() {
					// TODO Auto-generated method stub
					Apps.start(id);
					 HttpResponse response = HttpRequest
						        .post("http://maotouying.bceapp.com/spider.htm")
						        .form("id", ""+id).form("cid", ""+cid)
						        .send();
					 response.body();
				}
			}).start();
		} catch (Exception e) {
			e.printStackTrace();
		}
		response.getWriter().append("ok");
		response.getWriter().flush();
	}
}
